<?php

namespace app\admin\model\sys;
use think\Model;
use app\common\model\Base;


class Admin extends Base
{
    // protected $name = 'Admin';

	// protected $pk = 'id';
    public function groups(){
        return $this->belongsTo(AuthGroup::class,'group_id');
    }

    /**
     * 新增前，对数据进行特殊处理
     * @param Model $model
     * @return mixed|void
     */
    public static function onBeforeInsert(Model $model)
    {
        $model->password = password_hash($model->password,PASSWORD_BCRYPT);
        return true;
    }
    /**
     * 更新前，对数据进行特殊处理
     * @param Model $model
     * @return mixed|void
     */
    public static function onBeforeUpdate(Model $model)
    {
        if ($model->password) {
            $model->password = password_hash($model->password,PASSWORD_BCRYPT);
        }else{
            unset($model->password);
        }
        return true;
    }

}